<%extends"admin/base.html"%><%block content%>
<div class="layui-card">
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-comm" data-type="send">批量发送验证邮件</button>
        </div>
        <table id="LAY-app-content-user" lay-filter="LAY-app-content-user"></table>
        <script type="text/html" id="table-content-user">
           {{# if(d.state != true){ }}<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="send"><i class="layui-icon layui-icon-email"></i>发送验证邮件</a>{{#  } else { }}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-praise"></i>已验证</a>{{# } }}
        </script>
        <script type="text/html" id="stateTpl">
        {{#  if(d.state == true){ }}
            <button class="layui-btn layui-btn-xs layui-btn-warm">激活</button>
          {{#  } else { }}
            <button class="layui-btn layui-btn-danger layui-btn-xs">未激活</button>
          {{#  } }}
        </script>
      </div>
</div>
<%endblock%>
<%block script%>
    //点击事件
    var active = {
      send: function(){
        var checkStatus = table.checkStatus('LAY-app-content-user')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }

        layer.confirm('确定发送邮件吗？', function(index) {

          $.each(checkData,function(index,item){
                 //执行 Ajax 后重载
                  $.ajax({
                    url: "<< url_for('admin.UserSendTokenEmail') >>",
                    data:{Id:item.Id},
                    success: function (returnData) {
                        if (returnData.status == 1) {
                            layer.msg('已发送，ID:'+item.Id);
                        }
                        else {
                            layer.msg('ID:'+item.Id+'，'+returnData.info);
                        }
                     }
                  });
            });
            table.reload('LAY-app-content-user');
        });
      }
    }

    $('.layui-btn.layuiadmin-btn-user').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  table.render({
        elem: "#LAY-app-content-user",
        url: "<< url_for('admin.UserList') >>",
        method:'post',
        cols: [[{type: "checkbox", fixed: "left"},
            {field: "Id",width: 100,title: "ID",sort: !0},
            {field: "nickname", title: "昵称"},
            {field: "email", title: "邮箱"},
            {field: "createTime",title: "注册时间"},
             {field: "state",title: "状态",templet: "#stateTpl"},
            {field: "leacots_count", title: "留言数", sort: !0},
            {field: "reply_count", title: "评论数", sort: !0},
            {title: "操作",width: 150,align: "center",fixed: "right",toolbar: "#table-content-user"}
        ]],
        page: !0,
        limit: 15,
        limits: [10, 15, 20, 25, 30],
        text: {
            none: '暂无相关数据',
            error:'对不起，加载出现异常！'
        }
    }), table.on("tool(LAY-app-content-user)", function (t) {
        e=t.data;
        if("send" === t.event)
        {
            layer.confirm("确定发送验证邮件吗？", function (er) {
               layer.close(er)
                $.ajax({
                url: "<< url_for('admin.UserSendTokenEmail') >>",
                data:{Id:e.Id},
                success: function (returnData) {
                    if (returnData.status == 1) {
                        table.reload('LAY-app-content-user');
                        layer.msg('已发送，ID:'+item.Id);
                    }
                    else {
                        layer.msg('ID:'+item.Id+'，'+returnData.info);
                    }
                 }
              });
            })
        }
    })
    $('.layui-nav-item').removeClass('layui-this');
    $('#admin_user_nav').addClass('layui-this');
<%endblock%>